package com.hot100;
import java.util.*;
public class Solution128 {
    public int longestConsecutive(int[] nums) {
        Map<Integer,Integer> map =new HashMap<>();
        int res = 0;
        for (int num : nums) {
            if (!map.containsKey(num)) {
                int left = map.getOrDefault(num - 1, 0);
                int right = map.getOrDefault(num + 1, 0);
                int cur = right + left + 1;
                res = Math.max(res, cur);
                map.put(num, cur);
                map.put(num - left, cur);
                map.put(num + right, cur);
            }
        }
        return res;
    }
}
